<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>关键字过滤</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"><!-- 确保适当的绘制和触屏缩放 -->
    <link rel="stylesheet" href="{$url_css}bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="{$url_css}admin.css" type="text/css">
    <script type="text/javascript" src="{$url_js}jquery-1.12.0.min.js"></script>
    <script type="text/javascript" src="{$url_js}calendar/WdatePicker.js"></script>
</head>
<body>
<div class="container" style="width:96%">
    <table class="table table-bordered table-striped" align="center" id="list">
        <tr>
            <td class="col-xs-1 vc" colspan="2">添加关键字</td>
        </tr>
        <tr>
            <td width="150">关键词</td>
            <td width="90%">
                <textarea class="form-control" id="keywords" style="width: 400px;height: 120px"></textarea>
            </td>
        </tr>
        <tr>
            <td  colspan="2"><input id="add_keywords" type="submit" class="btn btn-default" value="添加"></td>
        </tr>
    </table>
</div>

<div class="container" style="width:96%">

    <table class="table table-bordered table-striped" align="center">
        <tr>
            <th colspan="3">关键字</th>
        </tr>
            {foreach $filter as $v}
                <tr>
                    <td align="center" width="40px">
                        <div class="checkbox">
                            <label><input type="checkbox" class="checkall" name="delid[]" value="{$v.Id}"/></label>
                        </div>
                    </td>
                    <td>
                        <input type="text" class="form-control name" id="nameg" value="{$v.Word|html}"/>
                    </td>
                    <td width="100px">
                        <div class="btn-group btn-group-sm" role="group" style="width:100px">
                            <button class="btn btn-default del_keywords" mid="{$v.Id}">修改</button>
                            <a href="?do=keyword&id={$v.Id}" class="btn btn-danger delete">删除</a>
                        </div>
                    </td>
                </tr>
            {/foreach}
        <tr>
            <td colspan="3">
                <div class="checkbox">
                    <label><input id="select_all" type="checkbox" value=""/> 全选</label>
                 <button type="submit" class="btn btn-default delcheckboxs">删除</button>
                </div>
            </td>
        </tr>
        </table>
        {if {$v.Word|html}}
            <div style="text-align: right">{$pages}</div>
        {/if}
            </div>
{literal}

<script type="text/javascript">
    $("#add_keywords").click(function() {
        var content = $.trim($('#keywords').val());
        if (content.length == 0) {
            top.sweetAlert('出错了', '内容不能为空', 'error');
            return false;
        }
        $.ajax({
            url: 'filter.php?do=AddKeyword',
            type: 'post',
            data: {content:content},
            dataType: 'json',
            success: function (re) {
                top.swal(re, function () {
                    if(re.type == 'success'){
                        self.location.reload();
                    }
                });
            }
        });
    });

    //修改
    $(".del_keywords").click(function() {
        var obj = $(this).parent().parent().parent();
        var name = obj.find(".name").val();
        var id = $(this).attr("mid");
        if (name == '') {
            top.swal('出错了','请填写修改的内容','','error');
        }else{
            $.ajax({
                url: 'filter.php?do=Modify',
                type: 'post',
                data: {name:name,id:id},
                dataType: 'json',
                success: function (re) {
                    top.swal(re,function(){
                        self.location.reload();
                    });
                }
            })
        }
    });

    //删除选中
    $(".delcheckboxs").click(function() {
        top.swal({
            title: '确定要删除吗？',
            text: '删除后不可恢复！',
            type: "warning",
            showCancelButton: true,
            cancelButtonText:'取消',
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            closeOnConfirm: false
        }, function() {
            var str = '';
            $("input[name='delid[]']").each(function() {
                if ($(this).is(':checked')) {
                    str+=str != ''?',':'';
                    str+=$(this).val();
                }
            });

            if(str) {
                $.ajax({
                    url: 'filter.php?do=Moredel',
                    type: 'post',
                    data: {'id':str},
                    dataType: 'json',
                    success: function(re) {
                        top.swal(re,function(){
                            self.location.reload();
                        });
                    }
                })
            }
        })
    });

    //全选
    $('#select_all').click(function() {
        if ($(this).prop('checked')) {
            $('.checkall').prop('checked', true);
        } else {
            $('.checkall').prop('checked', false);
        }
    });

    //删除
    $(".delete").click(function(){
        var url = self.location.pathname + $(this).attr("href");
        top.__confirm('确定要删除吗？','删除后不可恢复！', url, self);
        return false;
    });
</script>
{/literal}
</body>
</html>